{
  LX Result module

  Based on modo's SDK lxresult.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).

}


unit Lx_Result;

{$mode objfpc}{$H+}

interface

type
  { This type is not defined in FPC but is used on several SDK units
    like Lx_Render, Lx_Particle and Lx_Deform}

  PPSingle  = ^PSingle;

  { This type is not defined in FPC but is used on several SDK units
    like Lx_Particle }

  PUInt32   = ^UInt32;
  PPUInt32  = ^PUInt32;

  PLxResult = ^LxResult;
  LxResult  = HRESULT;

const
  LXe_FAILED      = LxResult($80000000);
  LXe_OK          = LxResult($0       );
  LXe_TRUE        = LxResult($0       );
  LXe_FALSE       = LxResult($1       );

  LXeSYS_IO       = $400;
  LXeSYS_PLUG     = $410;
  LXeSYS_IMAGE    = $420;
  LXeSYS_OPAL1    = $430;
  LXeSYS_OPAL2    = $440;
  LXeSYS_FONT     = $450;
  LXeSYS_ADISP    = $460;
  LXeSYS_AWIN     = $470;
  LXeSYS_CMDS     = $480;
  LXeSYS_IMSG     = $490;
  LXeSYS_COMP     = $500;
  LXeSYS_ITEM     = $510;
  LXeSYS_MESH     = $520;
  LXeSYS_BOOT     = $530;
  LXeSYS_FRAME    = $540;
  LXeSYS_REND     = $550;
  LXeSYS_SCRIPT   = $560;
  LXeSYS_QUERY    = $570;
  LXeSYS_UIIMAGE  = $580;
  LXeSYS_INPUTMAP = $590;
  LXeSYS_AFILE    = $600;
  LXeSYS_LOG      = $610;
  LXeSYS_VALUE    = $620;
  LXeSYS_NETWORK  = $630;
  LXeSYS_RENDER   = $640;
  LXeSYS_EVAL     = $650;
  LXeSYS_DEFORM   = $660;

function LXxGOODCODE(const m, v: Integer) : LxResult;
function LXxFAILCODE(const m, v: Integer) : LxResult;
function LXx_FAIL   (const r:    Integer) : Boolean ;
function LXx_OK     (const r:    Integer) : Boolean ;
function LXx_OKNI   (const r:    Integer) : Boolean ;

function LXe_INFO          : LxResult;
function LXe_WARNING       : LxResult;
function LXe_NOTIMPL       : LxResult;
function LXe_OUTOFMEMORY   : LxResult;
function LXe_INVALIDARG    : LxResult;
function LXe_NOINTERFACE   : LxResult;
function LXe_ABORT         : LxResult;
function LXe_NOACCESS      : LxResult;
function LXe_OUTOFBOUNDS   : LxResult;
function LXe_NOTFOUND      : LxResult;
function LXe_STARTUP       : LxResult;
function LXe_DISABLED      : LxResult;
function LXe_CKPTOVERFLOW  : LxResult;
function LXe_ALREADYEXISTS : LxResult;
function LXe_NOTAVAILABLE  : LxResult;
function LXe_CRASH         : LxResult;
function LXe_SHORTBUFFER   : LxResult;

implementation

function LXxGOODCODE(const m, v: Integer) : LxResult; inline;
begin
  Result := LxResult(((m shl 16) and $7FFF0000) or (v and $FFFF));
end;
function LXxFAILCODE(const m, v: Integer) : LxResult; inline;
begin
  Result := LxResult(LXe_FAILED or ((m shl 16) and $7FFF0000) or (v and $FFFF));
end;
function LXx_FAIL   (const r:    Integer) : Boolean ; inline;
begin
  Result := ((r and LXe_FAILED) <> 0);
end;
function LXx_OK     (const r:    Integer) : Boolean ; inline;
begin
  Result := (not LXx_FAIL(r));
end;
function LXx_OKNI   (const r:    Integer) : Boolean ; inline;
begin
  Result := (LXx_OK(r) or (r = LXe_NOTIMPL));
end;

function LXe_INFO          : LxResult; inline;
begin
  Result := LXxGOODCODE(0,  1);
end;
function LXe_WARNING       : LxResult; inline;
begin
  Result := LXxGOODCODE(0,  2);
end;
function LXe_NOTIMPL       : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  1);
end;
function LXe_OUTOFMEMORY   : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  2);
end;
function LXe_INVALIDARG    : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  3);
end;
function LXe_NOINTERFACE   : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  4);
end;
function LXe_ABORT         : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  7);
end;
function LXe_NOACCESS      : LxResult; inline;
begin
  Result := LXxFAILCODE(0,  9);
end;
function LXe_OUTOFBOUNDS   : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 21);
end;
function LXe_NOTFOUND      : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 23);
end;
function LXe_STARTUP       : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 24);
end;
function LXe_DISABLED      : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 25);
end;
function LXe_CKPTOVERFLOW  : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 26);
end;
function LXe_ALREADYEXISTS : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 27);
end;
function LXe_NOTAVAILABLE  : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 28);
end;
function LXe_CRASH         : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 29);
end;
function LXe_SHORTBUFFER   : LxResult; inline;
begin
  Result := LXxFAILCODE(0, 30);
end;

end.
